<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/web/header.jsp" %>
<title>上传头像</title>
</head>
<body>
	<fieldset class="layui-elem-field layui-field-title"
		style="margin: 10px; padding: 15px;">
		<legend>图片列表</legend>
		<button type="button" class="layui-btn" id="test1">
			<i class="layui-icon">&#xe67c;</i>上传图片
		</button>
		<div class="layui-upload-list">
			<table class="layui-table">
				<thead>
					<tr>
						<th width="5%">文件名</th>
						<th width="10%">图片</th>
						<th width="10%">操作</th>
					</tr>
				</thead>
				<tbody id="demoList2"></tbody>
			</table>
		</div>
	</fieldset>


<script type="text/javascript">
var code= '<%=request.getParameter("code")%>';

var upload = layui.upload;
// 类似submit的监听
renderUpload('test1',
		"/EmployeeUploadServlt",
		{code:code},
		function(res){
	      if(res.code == 1){
	    	  layer.msg("上传成功")
	    	  showPic(res.image)
	      }else{
	    	  layer.msg("成功失败")
	      }
	 });
init();
function init(){
	ajax('/employee',{action:'get',code:code}, 'json', function(data){
		var image = data.image;
		if(image) showPic(image);
		else $("#demoList2").html('');
	});
}

function delPic(code){
    openConfirm(function(){
        ajax('/employee',{action:'delPic',code:code},'text', function(data){
            if(1 == data){
                layer.msg("删除成功",init);
            }else{
                layer.msg("删除失败");
            }
        })
    }, "确认是否删除该记录？");
    
 }
 

	
function showPic(image){
	var html = "<tr><td>" + image
	+ "</td><td><img src='/images/" + image + "' class='layui-upload-img'></td>"
	+ "<td><input type='button' onclick='delPic(code)' class='layui-btn' value='删除'></td></tr>";
	$("#demoList2").html(html);
}

</script>
</body>
</html>